<?php defined('BASEPATH') or exit('No direct script access allowed');
class Statement_m extends MY_Model
{
	public function __construct(){
		parent::__construct();
		$this->set_table_name("transaction");
	}
	
	public function getStatement($userId, $fromdate, $todate, $transType){
		
		$sql ="SELECT du.username, t.*, c.name AS channel_name " 
		." \nFROM l_transaction t INNER JOIN default_users du ON du.id = t.user_id LEFT JOIN l_channel c ON c.id = t.channel_id "
		." \nWHERE t.user_id = " .((int)$userId)
		." AND date(t.settle_date) BETWEEN  '" . $fromdate->format("Y-m-d")."'"
		." AND '".$todate->format("Y-m-d")."'";
		if($transType){
			$sql.=$transType!=='BET' 
			?" AND t.trans_type = '".$transType."'"
			:" AND t.trans_type NOT IN('DEPOSIT','WITHDRAW','BONUS','TRANSFER')";
		}

		$sql.=" ORDER BY t.trans_date";

		return $this->db->query($sql, array())->result();
	}
	
}